window.onload = function(){
	//抓取元素
	var video        = document.getElementById("myVideo");
	var playAndPause = document.getElementById("playVideo");
	var restart      = document.getElementById("restart");
	var speed	     = document.getElementById("speed");
	var backward     = document.getElementById("backward");
	var getLength    = document.getElementById("getLength");
	var msg	         = document.getElementById("msg");
	var fileUrl      = document.getElementById("videoFile").value;
	var loadVideo    = document.getElementById("loadVideo");
	var tol          = 0;
	/**获得视频的总时长**/
	var tol = video.duration;
	/*
	var i = setInterval(function(){
		if(video.readyState > 0){
			var minutes = parseInt(video.duration / 60,10);
			var seconds = video.duration % 60;
			clearInterval(i);
		}
	},200);
	*/
	/**1、同一按钮控制视频播放和暂停**/
	playAndPause.onclick = function(){
		if(video.paused){
			video.play();
			this.value = "播放";
		}else{
			video.pause();
			this.value = "暂停";
		}
		console.log(tol);
	}

	/**2、重新播放视频**/
	restart.onclick = function(){
		//video.currentTime 获得当前视频的播放长度
		video.currentTime = 0;
	}

	/**3、快进**/
	speed.onclick = function(){
		video.currentTime += 1;
		if(video.currentTime >= tol){
			console.log("视频播放结束");
			return;
		}
	}

	/**4、后退**/
	backward.onclick = function(){
		if(video.currentTime == 0){
			console.log("视频回到初始位置");
			return;
		}else{
			video.currentTime -= 1;
		}
	}

	/**5、检查浏览器是否支持视频格式**/
	if(video.canPlayType){
		//canPlayType返回 maybe probably 或者 空字符串
		var playMsg = video.canPlayType('video/mp4;codecs="avc1.4D401E,mp4a.40.2"');
		console.log(playMsg);
		if("" != playMsg){
			msg.vlaue += "mp4/H.264 is " + playMsg + " supported<br/>";
		}
		playMsg = video.canPlayType('video/ogg;codecs=theora');
		if("" != playMsg){
			msg.value += "ogg is " + playMsg + " supported<br/>";
		}
		playMsg = video.canPlayType('video/webm;codecs="vp8,vorbis"');
		if("" != playMsg){
			msg.value += "webm is " + playMsg + " supported<br/>";
		}
	}else{
		msg.innerHTML = "no video support";
	}

	/**6、更改文件**/
	// function getVideo(){
	// 	if(fileUrl != ''){
	// 		video.src = fileUrl;
	// 		video.load();
	// 		playAndPause.click();
	// 	}else{
	// 		errMessage("Enter a valid video URL");
	// 	}
	// }

	loadVideo.onclick = function(){
		if(fileUrl != ''){
			video.src = fileUrl;
			video.load();
			playAndPause.click();
		}else{
			errMessage("error");
		}
	}
}